<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status==='0'">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="update_time" label="下单时间">
          <template slot-scope="scope">{{ scope.row.create_time | dateFormat }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- 修改订单 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="editOrder(scope.row.order_id)"
            ></el-button>
            <!-- 订单位置 -->
            <el-button type="success" icon="el-icon-location" size="mini" @click="showProgressBox"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页功能 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[1, 10, 15, 20]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>

    <!-- 修改操作 -->
    <el-dialog title="提示" :visible.sync="editDialogVisible" width="50%" @close="showOrderClose">
      <el-form :model="editRuleForm" :rules="editRules" ref="editRuleForm" label-width="100px">
        <el-form-item label="省市区/县" prop="addres1">
          <el-cascader :options="cityData" v-model="editRuleForm.addres1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="addres2">
          <el-input v-model="editRuleForm.addres2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度条弹出框 -->
    <el-dialog title="物流进度条" :visible.sync="proDialogVisible" width="50%">
     <el-timeline :reverse="reverse">
    <el-timeline-item
      v-for="(activity, index) in progressInfo"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "./citydata.js";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      orderList: [],
      editDialogVisible: false,
      // 物流进度条显示隐藏
      proDialogVisible:false,
      // 物流进度条数据
      progressInfo:[],
      editRuleForm: {
        addres1: [],
        addres2: ""
      },
      //   验证规则
      editRules: {
        addres1: [
          {
            required: true,
            message: "请选择省市区/县",
            trigger: "blur"
          }
        ],
        addres2: [
          {
            required: true,
            message: "请填写详细地址",
            trigger: "blur"
          }
        ]
      },
      cityData
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取列表失败");
      }
      console.log(res);
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    // 分页操作
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum;
      this.getOrderList();
    },
    // 修改
    async editOrder(id) {
      console.log(id);

      const { data: res } = await this.$http.get("orders/" + id);
      if (res.meta.status !== 200) {
        return this.$message.error("修改失败");
      }
      this.editRuleForm = res.data;
      //   this.$message.success("修改成功");
      this.editDialogVisible = true;
      //   this.getOrderList();
    },
    showOrderClose() {
      this.$refs.editRuleForm.resetFields();
    },
    // 订单位置
    async showProgressBox() {
      const { data: res } = await this.$http.get("/kuaidi/1106975712662");
      if (res.meta.status !== 200) {
        return this.$message.error("获取物流进度失败");
      }
      this.progressInfo = res.data;
      this.proDialogVisible=true
      console.log(this.progressInfo);
      
    }
    // editUser() {
    //   this.$refs.editRuleForm.validate(async valid => {
    //     if (!valid) return this.$message.error("验证失败");
    //     const { data: res } = await this.$http.put("orders/" + id);
    //     if (res.meta.status !== 200) {
    //       return this.$message.error("修改失败");
    //     }
    //     this.editRuleForm = res.data;
    //   });
    // }
  }
};
</script>

<style lang="less" scope>
</style>